﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CloudPms.Common.Utils;
using CloudPms.Domain.Interface;
using CloudPms.Domain.Repository;
using Microsoft.Practices.Unity;

namespace CloudPms.Logic.Business
{
    /// <summary>
    /// 酒店营业日缓存存储与更新服务
    /// <para>--------------------------</para>
    /// <para>@Author: cnalexi@gmail.com</para> 
    /// <para>@Create: 2012/10/06</para>  
    /// <example>
    /// <code>
    /// var bizDayCache = HotelBizDayCache.Instance;
    /// </code>
    /// </example> 
    /// </summary>
    public class HotelBizDayCache
    {
        private static volatile HotelBizDayCache _instance;
        private static readonly object lockThis = new object();
        private readonly IUnityContainer container = UnityContainerService.GetContainer();

        private static volatile IDictionary<string, string> _hotelConnection = new Dictionary<string, string>();

        private HotelBizDayCache()
        {
        }

        public static HotelBizDayCache Instance
        {
            get
            {
                if (_instance == null)
                {
                    lock (lockThis)
                    {
                        if (_instance == null)
                        {
                            _instance = new HotelBizDayCache();
                        }
                    }
                }
                return _instance;
            }
        }

        public void Initialization()
        {
            var bizDayRep = container.Resolve<IHotelBizDayRepository>();

            var hotelBizdays = bizDayRep.GetAll(GlobalCode.ROOT_HOTEL_ID);

            var xx = new KeyValuePair<string, string>("1,", "2");

            _hotelConnection = hotelBizdays.ToDictionary(o=>o.ID,o=>o.ConnectionString);

            //

        }

        public IDictionary<string, string> GetHotelConnection()
        {
            return _hotelConnection;
        }
    }
}
